import instacne from "../request";
import type { Ref } from "vue";

//分页
interface CommodityClassification {
  keyword?: string | Ref<string>;
  pageNum?: number | Ref<number>;
  pageSize?: number | Ref<number>;
  parentId?: number | Ref<number>;
  product?: string | Ref<string>;
  type?: string | Ref<number>;
}
//list返回
interface CommodityClassListItem {
  flashPromotionCount: number;
  flashPromotionId: number;
  flashPromotionLimit: number;
  flashPromotionPrice: number;
  flashPromotionSessionId: number;
  id: number;
  product: {};
  productId: number;
  sort: number;
}
//分页返回
interface CommodityClass {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: CommodityClassListItem[];
}
/**
 * 查询商品分类
 */
interface IProductCategoryChildrenItem {
  description: string;
  icon: string;
  id: number;
  keywords: string;
  level: number;
  name: string;
  navStatus: number;
  parentId: number;
  productCount: number;
  productUnit: string;
  showStatus: number;
  sort: number;
}
//品牌分类
interface IProductCategory {
  bigPic: string;
  brandStory: string;
  factoryStatus: string;
  firstLetter: string;
  id: number;
  logo: string;
  name: string;
  productCommentCount: string;
  productCount: string;
  showStatus: string;
  sort: number;
}

interface IProductCategoryRes {
  children: IProductCategoryChildrenItem[];
  description: string;
  icon: string;
  id: number;
  keywords: string;
  level: number;
  name: string;
  navStatus: number;
  parentId: number;
  productCount: number;
  productUnit: string;
  showStatus: number;
  sort: number;
}

const getProductCategoryList = (): Promise<IProductCategoryRes> => {
  return instacne.get("/productCategory/list/withChildren", {});
};

/**
 * 创建商品
 */
interface IProductCreateMemberPriceListItem {
  id: number;
  memberLevelId: number;
  memberLevelName: string;
  memberPrice: number;
  productId: number;
}

interface IProductCreateProductRelationListItem {
  id: number;
  prefrenceAreaId: number;
  productId: number;
}

interface IProductCreateAttributeValueListItem {
  id: number;
  productAttributeId: number;
  productId: number;
  value: string;
}

interface IProductCreateFullReductionListItem {
  fullPrice: number;
  id: number;
  productId: number;
  reducePrice: number;
}

interface IProductCreactLadderListItem {
  count: number;
  discount: number;
  id: number;
  price: number;
  productId: number;
}

interface IProductCreactStockListItem {
  id: number;
  lockStock: number;
  lowStock: number;
  pic: string;
  price: number;
  productId: number;
  promotionPrice: number;
  sale: number;
  skuCode: string;
  spData: string;
  stock: number;
}

interface IProductCreactRelationListItem {
  id: number;
  productId: number;
  subjectId: number;
}

interface IProductCreateRes {
  albumPics: string;
  brandId: number;
  brandName: string;
  deleteStatus: number;
  description: string;
  detailDesc: string;
  detailHtml: string;
  detailMobileHtml: string;
  detailTitle: string;
  feightTemplateId: number;
  giftGrowth: number;
  giftPoint: number;
  id: number;
  keywords: string;
  lowStock: number;
  memberPriceList: IProductCreateMemberPriceListItem[];
  name: string;
  newStatus: number;
  note: string;
  originalPrice: number;
  pic: string;
  prefrenceAreaProductRelationList: IProductCreateProductRelationListItem[];
  previewStatus: number;
  price: number;
  productAttributeCategoryId: number;
  productAttributeValueList: IProductCreateAttributeValueListItem[];
  productCategoryId: number;
  productCategoryName: string;
  productFullReductionList: IProductCreateFullReductionListItem[];
  productLadderList: IProductCreactLadderListItem[];
  productSn: string;
  promotionEndTime: "2023-04-10T06:24:46.041Z";
  promotionPerLimit: number;
  promotionPrice: number;
  promotionStartTime: "2023-04-10T06:24:46.041Z";
  promotionType: number;
  publishStatus: number;
  recommandStatus: number;
  sale: number;
  serviceIds: string;
  skuStockList: IProductCreactStockListItem[];
  sort: number;
  stock: number;
  subTitle: string;
  subjectProductRelationList: IProductCreactRelationListItem[];
  unit: string;
  usePointLimit: number;
  verifyStatus: number;
  weight: number;
}

const getProductCreateList = (): Promise<IProductCreateRes> => {
  return instacne.post("/mall-admin/product/create", {});
};

//商品分类
const getCommodityClassification = (
  data?: CommodityClassification
): Promise<CommodityClass> => {
  return instacne.get("/productCategory/list/0", {
    params: data,
  });
};
//商品分类的编辑

const getCommodityEditor = (
  data: string
): Promise<IProductCategoryChildrenItem> => {
  return instacne.get(`productAttribute/${data}`);
};
//商品分类的删除
const postProductDeletion = (data: number) => {
  return instacne.post(`/productCategory/delete/${data}`);
};

//查看商品下级
const getproductSubordinate = (
  data?: CommodityClassification
): Promise<CommodityClass> => {
  return instacne.get(
    `productCategory/list/${data?.parentId}?pageNum=${data?.pageNum}&pageSize=${data?.pageSize}`
  );
};
//品牌管理
const getBrandManagement = (
  data?: CommodityClassification
): Promise<CommodityClass> => {
  return instacne.get("/brand/list", {
    params: data,
  });
};
//添加品牌
const postaddBrand = (data: any) => {
  return instacne.post("brand/create", data);
};
//删除品牌
const getremoveBrand = (data: Number) => {
  return instacne.get(`brand/delete/${data}`);
};
//品牌管理的编辑
const getbrandEditor = (data: number): Promise<IProductCategory> => {
  return instacne.get(`brand/${data}`);
};
//品牌的修改
const postbrandModification = (data: IProductCategory) => {
  return instacne.post(`brand/update/${data.id}`, data);
};
//商品列表
const getProductList = (
  data?: CommodityClassification
): Promise<CommodityClass> => {
  return instacne.get("/product/list", {
    params: data,
  });
};
//属性管理
const ProductAttribute = (
  data?: CommodityClassification
): Promise<CommodityClass> => {
  return instacne.get("productAttribute/category/list", { params: data });
};
//当前属性列表
const getattributeList = (
  data?: CommodityClassification
): Promise<CommodityClass> => {
  return instacne.get(
    `productAttribute/list/${data?.parentId}?pageNum=${data?.pageNum}&pageSize=${data?.pageSize}&type=${data?.type}`
  );
};
//商品属性的添加
const postattributeAddition = (data: string) => {
  return instacne.post("productAttribute/category/create", data);
};
//商品属性的删除
const postrmover = (data: number) => {
  return instacne.get(`productAttribute/category/delete/${data}`);
};
interface userDisplay {
  id?: number;
  status?: string;
}
//商品上下线
const productUpload = (data: userDisplay) => {
  return instacne.post(
    `/product/update/publishStatus?ids=${data.id}&publishStatus=${data.status}`
  );
};
//新品品上下线
const postnewStatus = (data: userDisplay) => {
  return instacne.post(
    `/product/update/newStatus?ids=${data.id}&newStatus=${data.status}`
  );
};
//新品品上下线
const postrecommandStatus = (data: userDisplay) => {
  return instacne.post(
    `/product/update/recommendStatus?ids=${data.id}&recommendStatus=${data.status}`
  );
};
export {
  getProductCategoryList,
  getCommodityClassification,
  getBrandManagement,
  getProductList,
  ProductAttribute,
  getproductSubordinate,
  getCommodityEditor,
  postProductDeletion,
  getbrandEditor,
  postaddBrand,
  postbrandModification,
  getremoveBrand,
  postrmover,
  postattributeAddition,
  getattributeList,
  productUpload,
  postnewStatus,
  postrecommandStatus,
};
export type { IProductCategoryChildrenItem, IProductCategory };
